package com.api.hg.web;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.hg.action.DoorAaction;
import com.api.hg.action.assetAction;
import com.api.sw.duban.util.LogTool;
import com.engine.common.util.ParamUtil;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import java.util.HashMap;
import java.util.Map;
//--缉私局、香洲海关、中山海关、九洲海关、斗门海关、高栏海关、湾仔海关、珠海保健中心、拱北海关技术中心、后勤管理中心
@Path("/hg")
public class AssetAction {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/assetActionAPI",false);
    @GET
    @Path("/getsubtree")
    @Produces({"text/plain"})
    public String getSubTree(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONObject tree=new JSONObject();
        try{
            assetAction assetAction=new assetAction();
            tree= assetAction.getSubTree(var1,var2);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        apidatas.put("tree",tree);
        return JSONObject.toJSONString(apidatas);
    }
    @GET
    @Path("/updmodelrole")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String UpdModelRole(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONObject tree=new JSONObject();
        JSONObject param=new JSONObject();
        String mess="";
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            String billid= Util.null2String(var1.getParameter("billid"));//建模数据ID
            String subid=Util.null2String(var1.getParameter("subid"));//分部ID
            String depid=Util.null2String(var1.getParameter("depid"));//部门ID
            String userid=Util.null2String(var1.getParameter("userid"));//人员ID
            String curruserid=user.getUID()+"";//当前人员ID
            String lx=Util.null2String(var1.getParameter("lx"));//权限类型  0:分部 1：部门
            param.put("billid",billid);
            param.put("subid",subid);
            param.put("depid",depid);
            param.put("userid",userid);
            param.put("curruserid",curruserid);
            param.put("lx",lx);
            assetAction assetAction=new assetAction();
            mess=assetAction.UpdModelRole(param);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        if("".equals(mess)){
            apidatas.put("flag",true);
        }else{
            apidatas.put("flag",false);
            apidatas.put("mess",mess);
        }

        return JSONObject.toJSONString(apidatas);
    }
    @GET
    @Path("/getmenu")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getMenu(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{

            DoorAaction assetAction=new DoorAaction();
            apidatas=assetAction.getDoorData(var1,var2);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    @GET
    @Path("/getmenudata")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getMenuData(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{

            DoorAaction assetAction=new DoorAaction();
            apidatas=assetAction.getMenuData(var1,var2);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    /*
        关保数据销账
     */
    @GET
    @Path("/tablelist")
    @Produces({"text/plain"})
    public String tablelist(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getTableData(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    /*
        关保数据销账
     */
    @POST
    @Path("/zcxz")
    @Produces({"text/plain"})
    public String zcxz(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.CanlenCheck(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    /*
        关保数据销账
     */
    @POST
    @Path("/zcxzqr")
    @Produces({"text/plain"})
    public String zcxzqr(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.CanlenQr(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    //CalenCanlen
    //确认后 撤销
    @POST
    @Path("/calencanlen")
    @Produces({"text/plain"})
    public String CalenCanlen(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.CalenCanlen(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/getzcinfo")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getZcinfo(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{

            assetAction assetAction=new assetAction();
            zcinfo=assetAction.getZcinfo(var1,var2);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        apidatas.put("data",zcinfo);
        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/getInizcjson")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getIniZcJson(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{

            assetAction assetAction=new assetAction();
            zcinfo=assetAction.getIniZcJson(var1,var2);
        }catch(Exception e){
            log.writeLog("getInizcjson"+e.getMessage());
        }
        apidatas.put("data",zcinfo);
        return JSONObject.toJSONString(apidatas);
    }

    @POST
    @Path("/getswzcinfo")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getSwZcinfo(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getTableDataSW(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        apidatas.put("data",zcinfo);
        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/getswedzcinfo")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getSwEdZcinfo(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getEditTableDataSW(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        apidatas.put("data",zcinfo);
        return JSONObject.toJSONString(apidatas);
    }

    /**
     * 帐实关联页面获取关保资产信息
     * @param var1
     * @param var2
     * @return
     */
    @POST
    @Path("/getgbzcinfo")
    @Produces({"text/plain"})
    public String getGbZcinfo(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getTableDataG(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/getgbedzcinfo")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getGbEdZcinfo(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getEditTableDataG(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/newxz")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String NewXiaoz(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        String errormess="";
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            errormess=assetAction.XiaoZhang(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }
        if(!"".equals(errormess)){
            apidatas.put("flag", false);
            apidatas.put("mess", errormess);
        }else{
            apidatas.put("flag", true);
        }
        return JSONObject.toJSONString(apidatas);
    }
    @POST
    @Path("/getxzqrtable")
    @Produces({"text/plain"})
    //public String UpdModelRole(JSONObject json){
    public String getXzQrTableData(@Context HttpServletRequest var1, @Context HttpServletResponse var2){
        Map<String, Object> apidatas = new HashMap<String, Object>();
        JSONArray zcinfo=new JSONArray();
        String errormess="";
        try{
            User user = HrmUserVarify.getUser(var1, var2);
            assetAction assetAction=new assetAction();
            apidatas=assetAction.getXzQrTableData(ParamUtil.request2Map(var1),user);
        }catch(Exception e){
            log.writeLog(e.getMessage());
        }

        return JSONObject.toJSONString(apidatas);
    }
}
